package com.shouxin.attendance.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shouxin.attendance.R;
import com.shouxin.attendance.database.model.SwipeCardHistory;

import java.util.List;

public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.Holder> {

    private List<SwipeCardHistory> historyList;

    private LayoutInflater layoutInflater;

    public HistoryAdapter(List<SwipeCardHistory> historyList, LayoutInflater layoutInflater) {
        this.historyList = historyList;
        this.layoutInflater = layoutInflater;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new Holder(layoutInflater.inflate(R.layout.layout_history_list_item, parent, false));
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        final SwipeCardHistory history = historyList.get(position);

        holder.time.setText(history.getSendDate() + " " + history.getSendTime());
        holder.name.setText(history.getBaby().getName());
        holder.type.setText(history.getStatus() == 1 ? "上学" : "放学");
        holder.clazz.setText(history.getClazz().getName());
    }

    @Override
    public int getItemCount() {
        return historyList == null ? 0 : historyList.size();
    }

	static class Holder extends RecyclerView.ViewHolder {

        TextView time, name, clazz, type;

		Holder(View itemView) {
			super(itemView);

            time = (TextView) itemView.findViewById(R.id.history_item_time);
            name = (TextView) itemView.findViewById(R.id.history_item_name);
            clazz = (TextView) itemView.findViewById(R.id.history_item_class);
            type = (TextView) itemView.findViewById(R.id.history_item_type);
        }
    }
}
